 function utf8Encode(inputStr) {
     return inputStr

    var outputStr = "";



    for (var i = 0; i < inputStr.length; i++) {

        var temp = inputStr.charCodeAt(i);
        console.log(temp)



        //0xxxxxxx

        if (temp < 128) {

            outputStr += String.fromCharCode(temp);

        }

        //110xxxxx 10xxxxxx

        else if (temp < 2048) {

            outputStr += String.fromCharCode((temp >> 6) | 192);

            outputStr += String.fromCharCode((temp & 63) | 128);

        }

        //1110xxxx 10xxxxxx 10xxxxxx

        else if (temp < 65536) {

            outputStr += String.fromCharCode((temp >> 12) | 224);

            outputStr += String.fromCharCode(((temp >> 6) & 63) | 128);

            outputStr += String.fromCharCode((temp & 63) | 128);

        }

        //11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

        else {

            outputStr += String.fromCharCode((temp >> 18) | 240);

            outputStr += String.fromCharCode(((temp >> 12) & 63) | 128);

            outputStr += String.fromCharCode(((temp >> 6) & 63) | 128);

            outputStr += String.fromCharCode((temp & 63) | 128);

        }

    }



    return outputStr;

}


 function utf8Decode(inputStr) {

    var outputStr = "";

    var code1, code2, code3, code4;



    for (var i = 0; i < inputStr.length; i++) {

        code1 = inputStr[i];



        if (code1 < 128) {

            outputStr += String.fromCharCode(code1);

        }

        else if (code1 < 224) {

            code2 = inputStr[++i];

            outputStr += String.fromCharCode(((code1 & 31) << 6) | (code2 & 63));

        }

        else if (code1 < 240) {

            code2 = inputStr[++i];

            code3 = inputStr[++i];

            outputStr += String.fromCharCode(((code1 & 15) << 12) | ((code2 & 63) << 6) | (code3 & 63));

        }

        else {

            code2 = inputStr[++i];

            code3 = inputStr[++i];

            code4 = inputStr[++i];

            outputStr += String.fromCharCode(((code1 & 7) << 18) | ((code2 & 63) << 12) | ((code3 & 63) << 6) | (code2 & 63));

        }

    }



    return outputStr;

}


function getEncode64(inputstr) {

    var encode = encodeURI(inputstr);
    // 对编码的字符串转化base64
    var base64 = window.btoa(encode);
    // console.log(base64)
    return base64;
}


function getDecode(inputstr) {
    var str = "";
    var i = 0;
    console.log(inputstr)
    while (i < inputstr.length) {
        str += String.fromCharCode(inputstr[i])
        i = i + 1
    }
    console.log(str)
    // 对base64转编码
    var decode = window.atob(str);
    // 编码转字符串
    var str = decodeURI(decode);
//   return utf8Decode(inputstr)

  return str;
}


function getUnicode(inputstr) {
    return encodeURIComponent(inputstr)
}


function unicodeDecode(raw) {
    let rawStr = ''
    for(let i in raw) {
        rawStr = rawStr + String.fromCharCode(raw[i])
    }
  return decodeURIComponent(rawStr)
}

function Encode(inputStr,content) {
    if (inputStr == 'utf-8') {
         return utf8Encode(content)
    }
    if (inputStr == 'base64') {
        return getEncode64(content)
    }
    if (inputStr == 'unicode') {
        return getUnicode(content)
    }
    console.log("Error！")
}


function Decode(inputStr, content) {
    if (inputStr == 'utf-8') {
        return utf8Decode(content)
    }
    if (inputStr == 'base64') {
        return getDecode(content)
    }
    if (inputStr == 'utf-16') {
        return
    }
     if (inputStr == 'unicode') {
        return unicodeDecode(content)
    }
        console.log("Error！")
}


export {
   Encode,Decode
}
